#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:start.py
# author:张世航
# datetime:2024/12/21 01:29
# software: PyCharm
"""
this is function  description 
"""


# start.py
from controller.student_controller import add_student, delete_student, query_student_by_name
from controller.course_controller import add_course, delete_course, query_course_by_name
from controller.teacher_controller import add_teacher, delete_teacher, query_teacher_by_name

def main_menu():
    while True:
        print('1. 学生信息管理')
        print('2. 课程信息管理')
        print('3. 老师信息管理')
        print('0. 退出')
        index = input('请输入操作菜单选项: ')
        if index == '0':
            print("感谢使用，再见！")
            break
        elif index == '1':
            student_menu()
        elif index == '2':
            course_menu()
        elif index == '3':
            teacher_menu()
        else:
            print("无效的选项，请重新输入。")

def student_menu():
    while True:
        print('\n--- 学生信息管理 ---')
        print('1. 增加学生信息')
        print('2. 根据学生学号删除信息')
        print('3. 根据姓名查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令: ')
        if index_sql == '1':
            add_student_info()
        elif index_sql == '2':
            delete_student_info()
        elif index_sql == '3':
            query_student_info()
        elif index_sql == '0':
            break
        else:
            print("无效的选项，请重新输入。")

def add_student_info():
    sno = input('请输入学号: ')
    sname = input('请输入姓名: ')
    ssex = input('请输入性别: ')
    sage = int(input('请输入年龄: '))
    dno = input('请输入院系号: ')
    sclass = input('请输入班级: ')
    address = input('请输入家庭住址: ')
    add_student(sno, sname, ssex, sage, dno, sclass, address)
    print("学生信息添加成功！")

def delete_student_info():
    sno = input('请输入学号: ')
    delete_student(sno)
    print(f"学号为 {sno} 的学生信息已删除。")

def query_student_info():
    name = input('请输入姓名: ')
    students = query_student_by_name(name)
    if students:
        for student in students:
            print(f'学号: {student.Sno}, 姓名: {student.Sname}, 性别: {student.Ssex}, 年龄: {student.Sage}, 院系: {student.Dno}, 班级: {student.Sclass}, 地址: {student.address}')
    else:
        print("未找到相关学生信息。")

def course_menu():
    while True:
        print('\n--- 课程信息管理 ---')
        print('1. 增加课程信息')
        print('2. 根据课程号删除信息')
        print('3. 根据课程名查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令: ')
        if index_sql == '1':
            add_course_info()
        elif index_sql == '2':
            delete_course_info()
        elif index_sql == '3':
            query_course_info()
        elif index_sql == '0':
            break
        else:
            print("无效的选项，请重新输入。")

def add_course_info():
    cno = input('请输入课程号: ')
    cname = input('请输入课程名: ')
    chours = input('请输入学时: ')
    credit = float(input('请输入学分: '))
    tno = input('请输入教师编号: ')
    student_count = int(input('请输入学生选课人数: '))
    add_course(cno, cname, chours, credit, tno, student_count)
    print("课程信息添加成功！")

def delete_course_info():
    cno = input('请输入课程号: ')
    delete_course(cno)
    print(f"课程号为 {cno} 的课程信息已删除。")

def query_course_info():
    name = input('请输入课程名: ')
    courses = query_course_by_name(name)
    if courses:
        for course in courses:
            print(f'课程号: {course.Cno}, 课程名: {course.Cname}, 学时: {course.Chours}, 学分: {course.Credit}, 教师编号: {course.Tno}, 学生选课人数: {course.StudentCount}')
    else:
        print("未找到相关课程信息。")

def teacher_menu():
    while True:
        print('\n--- 老师信息管理 ---')
        print('1. 增加老师信息')
        print('2. 根据教师编号删除信息')
        print('3. 根据教师名查询信息')
        print('0. 返回上一层')
        index_sql = input('请输入操作指令: ')
        if index_sql == '1':
            add_teacher_info()
        elif index_sql == '2':
            delete_teacher_info()
        elif index_sql == '3':
            query_teacher_info()
        elif index_sql == '0':
            break
        else:
            print("无效的选项，请重新输入。")

def add_teacher_info():
    tno = input('请输入教师编号: ')
    tname = input('请输入教师名: ')
    dno = input('请输入院系号: ')
    salary = input('请输入工资: ')
    tmobile = input('请输入教师手机号: ')
    add_teacher(tno, tname, dno, salary, tmobile)
    print("老师信息添加成功！")

def delete_teacher_info():
    tno = input('请输入教师编号: ')
    delete_teacher(tno)
    print(f"教师编号为 {tno} 的老师信息已删除。")

def query_teacher_info():
    name = input('请输入教师名: ')
    teachers = query_teacher_by_name(name)
    if teachers:
        for teacher in teachers:
            print(f'教师编号: {teacher.Tno}, 教师名: {teacher.Tname}, 院系: {teacher.Dno}, 工资: {teacher.Salary}, 手机号: {teacher.Tmobile}')
    else:
        print("未找到相关老师信息。")

if __name__ == '__main__':
    main_menu()